package com.asl.website.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.asl.website.service.domain.ServiceContentDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.asl.common.annotation.Log;
import com.asl.common.core.controller.BaseController;
import com.asl.common.core.domain.AjaxResult;
import com.asl.common.enums.BusinessType;
import com.asl.website.service.domain.BizService;
import com.asl.website.service.service.IBizServiceService;
import com.asl.common.utils.poi.ExcelUtil;
import com.asl.common.core.page.TableDataInfo;

/**
 * 服务项目Controller
 * 
 * @author ruoyi
 * @date 2025-05-21
 */
@RestController
@RequestMapping("/service/service")
public class BizServiceController extends BaseController
{
    @Autowired
    private IBizServiceService bizServiceService;

    /**
     * 获取服务内容（支持多语言）
     */
    @GetMapping("/content")
    public AjaxResult getServiceContent(
            @RequestHeader(value = "Accept-Language", defaultValue = "zh-CN") String acceptLanguage) {

        List<BizService> services = bizServiceService.selectBizServiceList(new BizService());
        if (services.isEmpty()) {
            return AjaxResult.error("未配置服务内容");
        }

        return AjaxResult.success(new ServiceContentDTO(services, acceptLanguage));
    }

    /**
     * 查询服务项目列表
     */
    @PreAuthorize("@ss.hasPermi('service:service:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizService bizService)
    {
        startPage();
        List<BizService> list = bizServiceService.selectBizServiceList(bizService);
        return getDataTable(list);
    }

    /**
     * 导出服务项目列表
     */
    @PreAuthorize("@ss.hasPermi('service:service:export')")
    @Log(title = "服务项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizService bizService)
    {
        List<BizService> list = bizServiceService.selectBizServiceList(bizService);
        ExcelUtil<BizService> util = new ExcelUtil<BizService>(BizService.class);
        util.exportExcel(response, list, "服务项目数据");
    }

    /**
     * 获取服务项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:service:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizServiceService.selectBizServiceById(id));
    }

    /**
     * 新增服务项目
     */
    @PreAuthorize("@ss.hasPermi('service:service:add')")
    @Log(title = "服务项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizService bizService)
    {
        return toAjax(bizServiceService.insertBizService(bizService));
    }

    /**
     * 修改服务项目
     */
    @PreAuthorize("@ss.hasPermi('service:service:edit')")
    @Log(title = "服务项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizService bizService)
    {
        return toAjax(bizServiceService.updateBizService(bizService));
    }

    /**
     * 删除服务项目
     */
    @PreAuthorize("@ss.hasPermi('service:service:remove')")
    @Log(title = "服务项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizServiceService.deleteBizServiceByIds(ids));
    }
}
